import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.List;
 
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

public class ChinatorParser{  
 
    private URL url;
 
    public ChinatorParser(String url)
    {
        try
        {
            this.url = new URL(url);
        }
        catch (Exception e)
        {
            throw new RuntimeException(e);
        }
    }
 
    public List<ChinatorMarker> parse() {
        SAXParserFactory factory = SAXParserFactory.newInstance();
 
        try
        {
            SAXParser parser = factory.newSAXParser();
            ChinatorHandler handler = new ChinatorHandler();
            parser.parse(this.getInputStream(), handler);
            return handler.getChinators();
        }
        catch (Exception e)
        {
            throw new RuntimeException(e);
        }
    }
 
    private InputStream getInputStream()
    {
        try
        {
            return url.openConnection().getInputStream();
        }
        catch (IOException e)
        {
            throw new RuntimeException(e);
        }
    }
}